home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / bbs / Hydra11s.lha / HBBS / Source / Doors_System / XPR / Main.C_Pre311096 < prev    next >
Text File  |  1996-10-30  |  39KB  |  1,598 lines

  1. /*
  2.  
  3.    XPR door
  4.    ========
  5.  
  6.    This door provides access to the XPR Libraries for HBBS so that you can up
  7.    and download files.
  8.  
  9.    the TRANSFER door will call this most of the time.  It takes the following options
  10.  
  11.    N_ND->ActiveDoor->SystemOptions
  12.    ===============================
  13.  
  14.    None.
  15.  
  16.    dooroptions
  17.    ===========
  18.  
  19.    <xpr<lib>.library>
  20.  
  21.    TAGS [NOWAREZ] [NOSYSTEM]
  22.  
  23.    W=<upload path>         filenames are added to this if open() fails..
  24.                            note: *** MUST *** be specified BEFORE any U=<file> parameter!
  25.  
  26.    D=<download path>       you should normally only specify one place and that should
  27.                              be HBBS:Nodes/NodeX/Playpen/ (or wherever the node's playpen is..)
  28.  
  29.                             IMPORTANT:  must have trailing / or :
  30.                             --> not any more! 9/jul/1996
  31.  
  32.    U=<file to upload>      you can specify more than one of these only if the protocol
  33.                              is a batch upload protocol
  34.                              e.g.
  35.                              U=dh2:warez/miggy/hotsoft.lha
  36.                              U=dh2:warez/miggy/newsoft.lha
  37.                              ....
  38.  
  39.    S                       tells xpr to skip files that are present in the current
  40.                            conference's download directories.
  41.  
  42.    C                       tells xpr to remove users credits for transferred files
  43.  
  44.    O=<xprlibrary options>  some options for the xpr library..
  45.  
  46.    E.G.  (examples are for node 3)
  47.  
  48.      to download users tagged files and remove creds
  49.  
  50.        XPR 3 xprzmodem.library TAGS C
  51.  
  52.      get some files into the node's playpen.
  53.  
  54.        XPR 3 xprzmodem.library S D=HBBS:Nodes/Node3/PlayPen/
  55.  
  56.  
  57.    todo
  58.    ====
  59.  
  60.    move files if they are fucked as soon as they are fclose'd
  61.    also need to call background filechecker here too..
  62.  
  63.    implement L=<text file with list of files to upload>
  64.  
  65.  
  66.    notes
  67.    =====
  68.  
  69.    You've no idea how much hassle this door was to write..! :-)
  70.  
  71.  
  72. */
  73.  
  74. #include <exec/types.h>
  75. #include <exec/memory.h>
  76. #include <dos/dos.h>
  77. #include <clib/exec_protos.h>
  78. #include <clib/dos_protos.h>
  79. #include <clib/alib_protos.h>
  80.  
  81. #include <stdlib.h>
  82. #include <string.h>
  83. #include <stdio.h>
  84. #include <ctype.h>
  85. #include <time.h>
  86.  
  87. #include <devices/serial.h>
  88. #include <devices/timer.h>
  89.  
  90. #include <dos/dosextens.h>
  91. #include <intuition/screens.h>
  92. #include <intuition/intuition.h>
  93. #include <intuition/gadgetclass.h>
  94. #include <libraries/gadtools.h>
  95. #include <diskfont/diskfont.h>
  96. #include <utility/utility.h>
  97. #include <graphics/gfxbase.h>
  98. #include <workbench/workbench.h>
  99. #include <graphics/scale.h>
  100. #include <clib/wb_protos.h>
  101. #include <clib/intuition_protos.h>
  102. #include <clib/gadtools_protos.h>
  103. #include <clib/graphics_protos.h>
  104. #include <clib/utility_protos.h>
  105. #include <clib/diskfont_protos.h>
  106.  
  107. #include "xpr_gui.h"
  108.  
  109. #ifdef __SASC
  110. int CXBRK(void) { return(0); }
  111. int _CXBRK(void) { return(0); }
  112. void chkabort(void) {}
  113. #endif
  114.  
  115. #include <HBBS/ANSI_Codes.h>
  116. #include <HBBS/Defines.h>
  117. #include <HBBS/types.h>
  118. #include <HBBS/structures.h>
  119. #include <HBBS/hbbscommon_protos.h>
  120. #include <HBBS/hbbscommon_pragmas.h>
  121. #include <HBBS/Hbbsnode_protos.h>
  122. #include <HBBS/Hbbsnode_pragmas.h>
  123.  
  124. struct Library *HBBSCommonBase=NULL;
  125. struct Library *HBBSNodeBase=NULL;
  126. struct TextFont *HBBSFont=NULL;
  127. struct BBSGlobalData *BBSGlobal=NULL;
  128. struct NodeData *N_ND=NULL;
  129. int N_NodeNum=-1;
  130. char outstr[1024];
  131. long __near __stack=32768;
  132.  
  133. struct FileBuffer
  134. {
  135.   struct Node node; // filename in ln_Name
  136.   BPTR FH;
  137.   ULONG BytesTransferred;
  138.   ULONG BlocksTransferred;
  139.   ULONG ActualSize;
  140.   BOOL Testing;
  141.   BOOL ReadFile;
  142.  
  143. };
  144.  
  145. #include "xproto.h"  // XPR protocol stuff...
  146.  
  147.  
  148. UBYTE ZModemCancel[] =
  149. {
  150.   24,24,24,24,24,24,24,24,24,24,
  151.    8, 8, 8, 8, 8, 8, 8, 8, 8, 8
  152. };
  153.  
  154. // *** Flags
  155.  
  156. BOOL TWindowOpen=FALSE;
  157. BOOL CheckConfPaths=FALSE;
  158.   // if set then xpr_fopen() has to check all the Conf->Download paths for an existing file
  159.   // and skip it if the file already exists.
  160. BOOL TakeCreds=FALSE;
  161.  
  162. // *** File Info
  163.  
  164. struct List *UL_FileList=NULL; // a list of FileBuffer nodes..
  165. LONG UL_Files=0;
  166.  
  167. struct List *DL_FileList=NULL; // a list of FileBuffer nodes..
  168. LONG DL_Files=0;
  169.  
  170. UBYTE *DL_Path=NULL;
  171. BOOL DL_PathOK=FALSE;
  172.  
  173. UBYTE *UL_Path=NULL;
  174. BOOL UL_PathOK=FALSE;
  175.  
  176. struct FileBuffer *CurrentFile=NULL;
  177. LONG CurrentFileNum=1;
  178.  
  179. #define T_SEND 1
  180. #define T_RECEIVE 2
  181.  
  182. ULONG TransferType=0;
  183.  
  184. // ** Stuff for the XPR bit..
  185.  
  186. UBYTE *xprlibname=NULL;
  187. UBYTE *xprlibopts=NULL;
  188.  
  189. struct Library *XProtocolBase;
  190. struct XPR_IO *xio;
  191.  
  192. struct timerequest *treq;
  193. struct MsgPort *tport;
  194. char timeropen;
  195.  
  196. struct IOExtSer *xpr_serio;
  197. struct MsgPort *NewPort,*OldPort;
  198.  
  199. // ************* Misc Functions ***************
  200.  
  201. VOID cleanup(ULONG num)
  202. {
  203.   if (HBBSNodeBase)
  204.   {
  205.     HBBS_CleanUpDoor();
  206.     CloseLibrary (HBBSNodeBase);
  207.   }
  208.  
  209.   if (HBBSCommonBase)
  210.   {
  211.     HBBS_CleanUpCommon();
  212.     CloseLibrary (HBBSCommonBase);
  213.   }
  214.  
  215.   if (num) printf("Door Error = %d\n",num);
  216.  
  217.   exit(0);
  218. }
  219.  
  220. static VOID init(char *name)
  221. {
  222.   if(!(HBBSCommonBase = OpenLibrary("HBBSCommon.library",0)))
  223.   {
  224.     cleanup(1);
  225.   }
  226.  
  227.   if (!(HBBS_InitCommon()))
  228.   {
  229.     cleanup(2);
  230.   }
  231.  
  232.   if(!(HBBSNodeBase = OpenLibrary("HBBSNode.library",0)))
  233.   {
  234.     cleanup(3);
  235.   }
  236.  
  237.   if (!(HBBS_InitDoor(N_NodeNum,name)))
  238.   {
  239.     cleanup(4);
  240.   }
  241.   SetProgramName(name);
  242. }
  243.  
  244.  
  245. // ************* Main Door Functions ***************
  246.  
  247. // Timer Routines..
  248.  
  249. long opentimer(void)
  250. {
  251.   if (!(treq=AllocVec(sizeof(struct timerequest),MEMF_CLEAR|MEMF_PUBLIC)))
  252.   {
  253.     return(-1);
  254.   }
  255.   if(!(tport=CreateMsgPort()))
  256.   {
  257.     FreeVec(treq);
  258.     return(-1);
  259.   }
  260.   treq->tr_node.io_Message.mn_ReplyPort=tport;
  261.   if (OpenDevice("timer.device",UNIT_VBLANK,(struct IORequest*)treq,0))
  262.   {
  263.     DeleteMsgPort(tport);
  264.     FreeVec(treq);
  265.     return(-1);
  266.   }
  267.   timeropen=1;
  268.   return(0);
  269. }
  270.  
  271. static void closetimer(void)
  272. {
  273.   if(treq)
  274.   {
  275.     if(timeropen) CloseDevice((struct IORequest*)treq);
  276.     if(tport) DeleteMsgPort(tport);
  277.     FreeVec(treq);
  278.   }
  279. }
  280.  
  281. void qtimer(ULONG micros)
  282. {
  283. /*
  284.   long secs=0;
  285.   if (micros > 1000000)
  286.   {
  287.     secs = micros / 1000000;
  288.     micros = micros % 1000000;
  289.   }
  290.   treq->tr_time.tv_micro=micros;
  291.   treq->tr_time.tv_secs=secs;
  292. */
  293.  
  294.   treq->tr_time.tv_micro=micros % 1000000;
  295.   treq->tr_time.tv_secs=micros / 1000000;
  296.  
  297.   treq->tr_node.io_Command=TR_ADDREQUEST;
  298.   SetSignal(0,1L<<tport->mp_SigBit);
  299.   SendIO((struct IORequest*)treq);
  300. }
  301.  
  302. BOOL GrabSerial( void )
  303. {
  304.   AbortSerRead(); // just in case there are any pending serial requests..
  305.  
  306.   if(!(NewPort=CreatePort(0,0)))
  307.     return(FALSE);
  308.  
  309.   OldPort=N_ND->SerWrite->IOSer.io_Message.mn_ReplyPort;
  310.  
  311.   N_ND->SerWrite->IOSer.io_Message.mn_ReplyPort=NewPort;
  312.   N_ND->SerRead->IOSer.io_Message.mn_ReplyPort=NewPort;
  313.  
  314.   xpr_serio=N_ND->SerWrite;
  315.  
  316.   SetSignal(0,1L<<OldPort->mp_SigBit);
  317.  
  318.   return(TRUE);
  319.  
  320. }
  321.  
  322. void ReleaseSerial( void )
  323. {
  324.  
  325.   N_ND->SerWrite->IOSer.io_Message.mn_ReplyPort=OldPort;
  326.   N_ND->SerRead->IOSer.io_Message.mn_ReplyPort=OldPort;
  327.  
  328.   if (NewPort) DeletePort(NewPort);
  329. }
  330.  
  331.  
  332.  
  333. // ************* XPR Functions ***************
  334.  
  335.  
  336. LONG __saveds __asm xpr_finfo(register __a0 STRPTR FileName,register __d0 LONG InfoType)
  337. {
  338.   struct FileInfoBlock FB;
  339.   BPTR FL;
  340.   LONG result=0;
  341.  
  342. #ifdef debugmode
  343.   printf("xpr_finfo, FileName = \"%s\" type = %ld\n",FileName,InfoType);
  344. #endif
  345.  
  346.   switch (InfoType)
  347.   {
  348.     case 1:
  349.  
  350.       if (TransferType==T_RECEIVE && DL_PathOK)
  351.       {
  352.         strcpy(outstr,DL_Path);
  353.         strcat(outstr,FileName);
  354.       }
  355.       else
  356.       {
  357.         strcpy(outstr,FileName);
  358.       }
  359.  
  360.       if(FL=Lock(outstr,SHARED_LOCK))
  361.       {
  362.         if (Examine(FL,&FB))
  363.         {
  364.           result=FB.fib_Size;
  365.         }
  366.         UnLock(FL);
  367.       }
  368.       else
  369.       {
  370.         DOOR_SysopText("Lock Failed!\r\n");
  371.       }
  372.       break;
  373.  
  374.     case 2:
  375.       result = 1; // always a binary transfer
  376.       break;
  377.   }
  378. #ifdef debugmode
  379.   printf("xpr_finfo, returning = %ld\n",result);
  380. #endif
  381.   return((LONG)result);
  382. }
  383.  
  384. LONG __saveds __asm xpr_ffirst(register __a0 STRPTR Buffer,register __a1 STRPTR Pattern)
  385. {
  386.  
  387.   #ifdef debugmode
  388.   printf("xpr_ffirst, pattern = \"%s\"\n",Pattern);
  389.   #endif
  390.  
  391.   if (UL_Files)
  392.   {
  393.     CurrentFile=(struct FileBuffer*)UL_FileList->lh_Head;
  394.     CurrentFileNum=1;
  395.     strcpy(Buffer,CurrentFile->node.ln_Name);
  396.   }
  397.  
  398.   #ifdef debugmode
  399.   printf("xpr_ffirst, buffer now = \"%s\"\n",Buffer);
  400.   #endif
  401.   return(1);
  402. }
  403.  
  404. LONG __saveds __asm xpr_fnext(register __d0 LONG OldState,register __a0 STRPTR Buffer,register __a1 STRPTR Pattern)
  405. {
  406.   #ifdef debugmode
  407.   printf("xpr_fnext, OldState = %ld, pattern = \"%s\"\n",OldState,Pattern);
  408.   #endif
  409.  
  410.   if (CurrentFileNum<UL_Files)
  411.   {
  412.     CurrentFile=(struct FileBuffer*)CurrentFile->node.ln_Succ;
  413.     CurrentFileNum++;
  414.     strcpy(Buffer,CurrentFile->node.ln_Name);
  415.     #ifdef debugmode
  416.     printf("xpr_fnext, filename: %s, returning 1",Buffer);
  417.     #endif
  418.     return((LONG)1);
  419.   }
  420.   #ifdef debugmode
  421.   printf("No more files for xpr_fnext\n");
  422.   #endif
  423.   return((LONG)0);
  424. }
  425.  
  426. LONG __saveds __asm xpr_gets(register __a0 STRPTR Prompt,register __a1 STRPTR Buffer)
  427. {
  428.   #ifdef debugmode
  429.   printf("xpr_gets, Prompt = \"%s\", Buffer = \"%s\"\n",Prompt,Buffer);
  430.   #endif
  431.   return((LONG)0);
  432. }
  433.  
  434. LONG __saveds __asm xpr_fopen(register __a0 STRPTR FileName,register __a1 STRPTR AccessMode)
  435. {
  436.   BPTR FL;
  437.   BOOL FileExists=FALSE;
  438.   UBYTE tmpfilename[1024],newname[1024];
  439.   struct ConfData *Conf=NULL;
  440.   struct Node *node;
  441.   struct NodeData *nd;
  442.  
  443.   #ifdef debugmode
  444.   sprintf(outstr,"xpr_open, file = \"%s\", mode = \"%s\"\r\n",FileName,AccessMode);
  445.   DOOR_SysopText(outstr);
  446.   #endif
  447.  
  448.   if (stricmp(AccessMode,"r")==0)
  449.   {
  450.     if (TransferType==T_RECEIVE)
  451.     {
  452.       // *C* check here for existance of file in the PartUploads dir and move it to the
  453.       // playpen.. Also check in the current conference's dl_paths (if in a conf..)
  454.  
  455.       if ((CheckConfPaths) && (Conf=FindConf()))
  456.       {
  457.         for (node=Conf->Download->lh_Head;!FileExists && node->ln_Succ;node=node->ln_Succ)
  458.         {
  459.           strcpy(tmpfilename,node->ln_Name);
  460.           strcat(tmpfilename,FileName);
  461.           if (PathOK(tmpfilename)) FileExists=TRUE;
  462.         }
  463.  
  464.         if (!FileExists) // now check in the other nodes playpen dirs to see if
  465.         {                // someone else is uploading the same file..
  466.           for (nd=(struct NodeData *)BBSGlobal->NodeList->lh_Head;!FileExists && nd->node.ln_Succ;nd=(struct NodeData*)nd->node.ln_Succ)
  467.           {
  468.             strcpy(tmpfilename,nd->NodeSettings.NodePlayPen);
  469.             AddPart(tmpfilename,FileName,1024);
  470.             if (PathOK(tmpfilename)) FileExists=TRUE;
  471.           }
  472.         }
  473.  
  474.         if (!FileExists)
  475.         {
  476.           // check in partupload directory and if present copy to playpen so user can
  477.           // resume the u/l..
  478.  
  479.           for (node=Conf->PartUpload->lh_Head;!FileExists && node->ln_Succ;node=node->ln_Succ)
  480.           {
  481.             sprintf(tmpfilename,"%s%s@%ld",node->ln_Name,FileName,N_ND->User.CallData.UserID);
  482.             if (PathOK(tmpfilename))
  483.             {
  484.               strcpy(newname,DL_Path);
  485.               AddPart(newname,FileName,1024);
  486.               Rename(tmpfilename,newname);    // *C* change and add a copy here if rename fails!!
  487.               FileExists=TRUE;
  488.             }
  489.           }
  490.           FileExists=FALSE; // as we don't want to skip anymore..
  491.         }
  492.  
  493.       }
  494.  
  495.       if ((FileExists) || (!DL_PathOK))
  496.       {
  497.         // file exists, no path specified
  498.         #ifdef debugmode
  499.         puts("file exists or no dlpath");
  500.         #endif
  501.         return(0); // this will cause the file to be SKIPPED
  502.       }
  503.  
  504.       CurrentFile=NULL;
  505.  
  506.       strcpy(tmpfilename,DL_Path);
  507.       AddPart(tmpfilename,FileName,1024);
  508.  
  509.       if (CurrentFile=(struct FileBuffer*)HBBS_CreateNode(tmpfilename,sizeof(struct FileBuffer)))
  510.       {
  511.         CurrentFile->Testing=TRUE;
  512.       }
  513.     }
  514.  
  515.     if (TransferType==T_SEND)
  516.     {
  517.       if (stricmp(FileName,CurrentFile->node.ln_Name)!=0)
  518.       {
  519.         printf("Where the fuck did this filename come from ??\n: %s\n",FileName);
  520.         return(0);
  521.       }
  522.     }
  523.   }
  524.   else // transfer is a download (i.e. user sending the BBS a file.
  525.   {
  526.     // transfer is a download, so add the path of the download directory
  527.     // to the FileName
  528.  
  529.     strcpy(tmpfilename,DL_Path);
  530.     strcat(tmpfilename,FileName);
  531.  
  532.     if (CurrentFile=(struct FileBuffer*)HBBS_CreateNode(tmpfilename,sizeof(struct FileBuffer)))
  533.     {
  534.       AddTail(DL_FileList,(struct Node*)CurrentFile);
  535.       DL_Files++;
  536.     }
  537.   }
  538.  
  539.   if (!CurrentFile) // *R* needed ?
  540.   {
  541.     return(0);
  542.   }
  543.  
  544.   switch(AccessMode[0])
  545.   {
  546.     case 'r':
  547.       // open the file, if it fails and we're sending a file then add the u/l path to the filename
  548.       CurrentFile->FH=Open(CurrentFile->node.ln_Name,AccessMode[1]=='+' ? MODE_READWRITE : MODE_OLDFILE);
  549.  
  550. /* not used here... see at param checking part of program!
  551.       if (!(CurrentFile->FH=Open(CurrentFile->node.ln_Name,AccessMode[1]=='+' ? MODE_READWRITE : MODE_OLDFILE)))
  552.       {
  553.         if (UL_PathOK && TransferType==T_SEND)
  554.         {
  555.           FreeStr(CurrentFile->node.ln_Name);
  556.           strcpy(tmpfilename,UL_Path);
  557.           AddPart(tmpfilename,FileName,1023);
  558.           if (CurrentFile->node.ln_Name=DupStr(tmpfilename))
  559.           {
  560.             CurrentFile->FH=Open(CurrentFile->node.ln_Name,AccessMode[1]=='+' ? MODE_READWRITE : MODE_OLDFILE);
  561.           }
  562.         }
  563.       }
  564. */
  565.       break;
  566.     case 'w':
  567.       // open file for writing, truncate old file if it exists
  568.       if (AccessMode[1]=='+')  // truncate file (well, delete it anyway)
  569.       {
  570.         if (FL = Lock(CurrentFile->node.ln_Name,ACCESS_WRITE))
  571.         {
  572.           UnLock(FL);
  573.           DeleteFile(CurrentFile->node.ln_Name);
  574.         }
  575.         CurrentFile->FH=Open(CurrentFile->node.ln_Name,MODE_READWRITE);
  576.       }
  577.       else
  578.       {
  579.         CurrentFile->FH=Open(CurrentFile->node.ln_Name,MODE_NEWFILE);
  580.       }
  581.       break;
  582.     case 'a':
  583.       // open file, seek to end, create new file if none exists.
  584.  
  585.       if (FL=Lock(CurrentFile->node.ln_Name,ACCESS_WRITE))
  586.       {
  587.         UnLock(FL);
  588.         if(CurrentFile->FH=Open(CurrentFile->node.ln_Name,MODE_READWRITE))
  589.         {
  590.           DOOR_SysopText("seeking..");
  591.           if (Seek(CurrentFile->FH,0,OFFSET_END) == -1) // error seeking ?
  592.           {
  593.             Close(CurrentFile->FH);
  594.             CurrentFile->FH = NULL;
  595.           } else DOOR_SysopText("ok!\r\n");
  596.         }
  597.       }
  598.       else
  599.       {
  600.         CurrentFile->FH=Open(CurrentFile->node.ln_Name,MODE_NEWFILE);
  601.       }
  602.       break;
  603.   }
  604.  
  605.   if (CurrentFile->FH==NULL) // open failed!
  606.   {
  607.     if (CurrentFile->Testing)
  608.     {
  609.       HBBS_FreeNode((struct Node*)CurrentFile,FALSE);
  610.     }
  611.     return(NULL);
  612.   }
  613.  
  614.   #ifdef debugmode
  615.   printf("xpr_fopen, returning %x\r\n",(LONG)CurrentFile);
  616.   #endif
  617.  
  618.  
  619.   return((LONG)CurrentFile);
  620. }
  621.  
  622. LONG __saveds __asm xpr_fclose(register __a0 struct FileBuffer *FileBuf)
  623. {
  624. #ifdef debugmode
  625.   printf("xpr_fclose, FileBuf->Filename = \"%s\" FileBuf->FH = %x\n",FileBuf->node.ln_Name,FileBuf->FH);
  626. #endif
  627.   if ((FileBuf) && (FileBuf->FH))
  628.   {
  629.     Close(FileBuf->FH);
  630.     if (FileBuf->Testing)
  631.     {
  632.       HBBS_FreeNode((struct Node*)FileBuf,FALSE);
  633.     }
  634.   }
  635.   return((LONG)0);
  636. }
  637.  
  638. LONG __saveds __asm xpr_fread(register __a0 APTR Buffer,register __d0 LONG Size,register __d1 long Count,register __a1 struct FileBuffer *FileBuf)
  639. {
  640.   LONG retval;
  641. #ifdef debugmode
  642.   printf("xpr_fread, Size = %ld, Count = %ld\n",Size,Count);
  643. #endif
  644.   // check params are ok..
  645.   if (!Size)
  646.   {
  647. #ifdef debugmode
  648.     puts("xpr_fread size = 0!");
  649. #endif
  650.     return(0);
  651.   }
  652. //  if (Buffer == NULL || FileBuf==NULL || FileBuf->FH==NULL || Size==0 || Count==0) return((LONG)0);
  653.   retval=Read(FileBuf->FH,Buffer,Size*Count);
  654. #ifdef debugmode
  655.   printf("xpr_fread returning %ld\n",retval);
  656. #endif
  657.  
  658.   if (retval) FileBuf->ReadFile=TRUE; // so we can determine if a file was skipped if it was
  659.                                       // already present on the user's machine (not the sysop's)
  660.  
  661.   return(retval);
  662. }
  663.  
  664. LONG __saveds __asm xpr_fwrite(register __a0 APTR Buffer,register __d0 LONG Size,register __d1 LONG Count,register __a1 struct FileBuffer *FileBuf)
  665. {
  666.   LONG retval;
  667. #ifdef debugmode
  668.   printf("xpr_write, Size = %ld, Count = %ld\n",Size,Count);
  669. #endif
  670.  
  671. //  return(Size * Count);
  672.  
  673.   // check params are ok..
  674. //  if (Buffer == NULL || FileBuf==NULL || FileBuf->FH==NULL || Size==0 || Count==0) return((LONG)0);
  675.   if (!Size)
  676.   {
  677. #ifdef debugmode
  678.     puts("xpr_fwrite size = 0!");
  679. #endif
  680.     return(0);
  681.   }
  682.   retval=Write(FileBuf->FH,Buffer,Size*Count);
  683. #ifdef debugmode
  684.   printf("xpr_write returning %ld\n",retval);
  685. #endif
  686.   return(retval);
  687. }
  688.  
  689. LONG __saveds __asm xpr_fseek(register __a0 struct FileBuffer *FileBuf,register __d0 LONG Offset,register __d1 LONG Origin)
  690. {
  691.   LONG Mode=-1;
  692.   LONG tmpval;
  693.  
  694. #ifdef debugmode
  695.   printf("xpr_seek, Offset = %ld, Origin = %ld\n",Offset,Origin);
  696. #endif
  697.  
  698.   // check params are ok..
  699.   if (FileBuf==NULL || FileBuf->FH==NULL) return((LONG)-1);
  700.  
  701.   switch(Origin)
  702.   {
  703.     case 0: Mode=OFFSET_BEGINNING; break;
  704.     case 1: Mode=OFFSET_CURRENT; break;
  705.     case 2: Mode=OFFSET_END; break;
  706.     default: return((LONG)-1);
  707.   }
  708.   tmpval=Seek(FileBuf->FH,Offset,Mode);
  709. #ifdef debugmode
  710.   printf("xpr_seek, seek() result = %ld\r\n",tmpval);
  711. #endif
  712.   return((tmpval==-1) ? (LONG)-1 : (LONG)0);
  713.  
  714. }
  715.  
  716. LONG __saveds __asm xpr_unlink(register __a0 STRPTR FileName)
  717. {
  718. #ifdef debugmode
  719.   printf("xpr_unlick, FileName = \"%s\"\n",FileName);
  720. #endif
  721.   return(DeleteFile(FileName));
  722. }
  723.  
  724. void xpr_closedisplay(void)
  725. {
  726. #ifdef debugmode
  727.   printf("xpr_closedisplay\n");
  728. #endif
  729.   return;
  730. }
  731.  
  732. LONG __saveds __asm xpr_displayupdate(register __a0 struct XPR_UPDATE *xu)
  733. {
  734.   long ud=xu->xpru_updatemask;
  735.   LONG tempnum;
  736.  
  737.   if(ud&XPRU_BYTES)
  738.   {
  739.     if (CurrentFile)
  740.     {
  741.       CurrentFile->BytesTransferred=xu->xpru_bytes;
  742.  
  743.       if (TWindowOpen)
  744.       {
  745.         GT_SetGadgetAttrs(XPRWinGadgets[XPRWin_Transferred],XPRWin,NULL,GTNM_Number,(LONG)xu->xpru_bytes,TAG_DONE);
  746.  
  747.         if (CurrentFile->ActualSize) tempnum=(LONG)((CurrentFile->BytesTransferred * 100) / CurrentFile->ActualSize); else tempnum=0;
  748.         GT_SetGadgetAttrs(XPRWinGadgets[XPRWin_Percent],XPRWin,NULL,GTNM_Number,(LONG)tempnum,TAG_DONE);
  749.  
  750.         tempnum=CurrentFile->ActualSize - CurrentFile->BytesTransferred;
  751.         GT_SetGadgetAttrs(XPRWinGadgets[XPRWin_Remaining],XPRWin,NULL,GTNM_Number,(LONG)tempnum,TAG_DONE);
  752.       }
  753.     }
  754.  
  755.   }
  756.  
  757.   if(ud&XPRU_PROTOCOL)
  758.   {
  759.     if (TWindowOpen)
  760.     {
  761.       GT_SetGadgetAttrs(XPRWinGadgets[XPRWin_Library],XPRWin,NULL,GTTX_Text,xu->xpru_protocol,TAG_DONE);
  762.     }
  763.   }
  764.   if(ud&XPRU_FILENAME)
  765.   {
  766.     if (TWindowOpen)
  767.     {
  768.       GT_SetGadgetAttrs(XPRWinGadgets[XPRWin_File],XPRWin,NULL,GTTX_Text,xu->xpru_filename,TAG_DONE);
  769.     }
  770.   }
  771.   if(ud&XPRU_FILESIZE)
  772.   {
  773.     if (TWindowOpen)
  774.     {
  775.       GT_SetGadgetAttrs(XPRWinGadgets[XPRWin_Size],XPRWin,NULL,GTNM_Number,(LONG)xu->xpru_filesize,TAG_DONE);
  776.     }
  777.  
  778.     if (CurrentFile)
  779.     {
  780.       CurrentFile->ActualSize=xu->xpru_filesize;
  781.     }
  782.   }
  783.   if(ud&XPRU_MSG)
  784.   {
  785.     if (TWindowOpen)
  786.     {
  787.       GT_SetGadgetAttrs(XPRWinGadgets[XPRWin_Message],XPRWin,NULL,GTTX_Text,xu->xpru_msg,TAG_DONE);
  788.     }
  789.  
  790.   }
  791.   if(ud&XPRU_BLOCKS)
  792.   {
  793.     if (CurrentFile)
  794.     {
  795.       CurrentFile->BlocksTransferred=xu->xpru_blocks;
  796.     }
  797.     if (TWindowOpen)
  798.     {
  799.       GT_SetGadgetAttrs(XPRWinGadgets[XPRWin_Blocks],XPRWin,NULL,GTNM_Number,(LONG)xu->xpru_blocks,TAG_DONE);
  800.     }
  801.   }
  802.   if(ud&XPRU_ERRORMSG)
  803.   {
  804.     if (TWindowOpen)
  805.     {
  806.       GT_SetGadgetAttrs(XPRWinGadgets[XPRWin_Message],XPRWin,NULL,GTTX_Text,xu->xpru_errormsg,TAG_DONE);
  807.     }
  808.   }
  809.  
  810.   if(ud&XPRU_DATARATE)
  811.   {
  812.     if (TWindowOpen)
  813.     {
  814.       GT_SetGadgetAttrs(XPRWinGadgets[XPRWin_CPS],XPRWin,NULL,GTNM_Number,(LONG)xu->xpru_datarate,TAG_DONE);
  815.     }
  816.   }
  817.   if(ud&XPRU_BLOCKSIZE)
  818.   {
  819.     if (TWindowOpen)
  820.     {
  821.       GT_SetGadgetAttrs(XPRWinGadgets[XPRWin_BlockSize],XPRWin,NULL,GTNM_Number,(LONG)xu->xpru_blocksize,TAG_DONE);
  822.     }
  823.   }
  824.   if(ud&XPRU_ERRORS)
  825.   {
  826.     if (TWindowOpen)
  827.     {
  828.       GT_SetGadgetAttrs(XPRWinGadgets[XPRWin_Errors],XPRWin,NULL,GTNM_Number,(LONG)xu->xpru_errors,TAG_DONE);
  829.     }
  830.   }
  831.  
  832.   /*
  833.   if(ud&XPRU_ELAPSEDTIME)printf("%d Elapsed Time\n",xu->xpru_elapsedtime);
  834.   if(ud&XPRU_EXPECTTIME) printf("%d ExpectTime\n",xu->xpru_expecttime);
  835.   if(ud&XPRU_BLOCKCHECK) printf("%d Block Check\n",xu->xpru_blockcheck);
  836.   */
  837.  
  838.   return(0);
  839. }
  840.  
  841. LONG __saveds __asm xpr_swrite(register __a0 APTR Buffer,register __d0 LONG Size)
  842. {
  843. #ifdef debugmode
  844.   printf("xpr_swrite, Size = %ld\n",Size);
  845. #endif
  846.   if (Size==0)
  847.   {
  848. #ifdef debugmode
  849.     puts("xpr_swrite invalid size!");
  850. #endif
  851.     return((LONG)0);
  852.   }
  853.  
  854.   xpr_serio->IOSer.io_Length=Size;
  855.   xpr_serio->IOSer.io_Data=Buffer;
  856.   xpr_serio->IOSer.io_Command=CMD_WRITE;
  857.   SetSignal(0,1L<<NewPort->mp_SigBit);
  858.   DoIO((struct IORequest *)xpr_serio);
  859. #ifdef debugmode
  860.   printf("xpr_swrite returning %ld\n",xpr_serio->IOSer.io_Error);
  861. #endif
  862.   return((LONG)xpr_serio->IOSer.io_Error);
  863. }
  864.  
  865.  
  866. LONG __saveds __asm xpr_chk4abort(void)
  867. {
  868.   struct IntuiMessage *im=0;
  869.   LONG retval=0;
  870.  
  871.   if(TWindowOpen)
  872.   {
  873.     if (im=(struct IntuiMessage *)GetMsg(XPRWin->UserPort))
  874.     {
  875.       // We've only got one type of message, so it must be the close gadget
  876.       // being pressed!
  877.  
  878.       ReplyMsg((struct Message *)im);
  879.       retval=-1;
  880.  
  881.     }
  882.   }
  883.  
  884.   if (CarrierLost()) retval=-1;
  885.  
  886. #ifdef debugmode
  887.   printf("xpr_chkabort returning %ld\n",retval);
  888. #endif
  889.   return(retval);
  890. }
  891.  
  892.  
  893. LONG __saveds __asm xpr_sread(register __a0 APTR Buffer,register __d0 LONG Size,register __d1 ULONG Timeout)
  894. {
  895.   ULONG WaitSigs,ReturnedSigs;
  896.  
  897.   LONG BytesWaiting,AmountToRead;
  898.  
  899.  
  900. #ifdef debugmode
  901.   printf("xpr_sread, Size = %ld, Timeout = %ld\n",Size,Timeout);
  902. #endif
  903.  
  904.   if (Size==0)
  905.   {
  906. #ifdef debugmode
  907.     puts("xpr_sread invalid size");
  908. #endif
  909.     return((LONG)0);
  910.   }
  911.  
  912.   if (CarrierLost()) return((LONG)-1);
  913.  
  914.   /* See how many bytes there are */
  915.  
  916.   xpr_serio->IOSer.io_Command=SDCMD_QUERY;
  917.   DoIO((struct IORequest *)xpr_serio);
  918.   BytesWaiting=xpr_serio->IOSer.io_Actual;
  919.  
  920.   if(!Timeout || BytesWaiting >= Size)
  921.   {
  922.     if(!BytesWaiting)
  923.     {
  924.       // no data to be read..
  925.       return(0);
  926.     }
  927.     else
  928.     {
  929.       // some data is waiting
  930.       if(BytesWaiting>Size) AmountToRead=Size;
  931.       xpr_serio->IOSer.io_Command=CMD_READ;
  932.       xpr_serio->IOSer.io_Data=Buffer;
  933.       xpr_serio->IOSer.io_Length=AmountToRead;
  934.       DoIO((struct IORequest *)xpr_serio);
  935.  
  936.       // return amount of bytes read
  937. #ifdef debugmode
  938.       printf("xpr_sread, returning %ld\n",AmountToRead);
  939. #endif
  940.       return((LONG)AmountToRead);
  941.     }
  942.   }
  943.  
  944.   xpr_serio->IOSer.io_Command=CMD_READ;
  945.   xpr_serio->IOSer.io_Data=Buffer;
  946.   xpr_serio->IOSer.io_Length=Size;
  947.  
  948.   SetSignal(0,1L<<NewPort->mp_SigBit);
  949.   SendIO((struct IORequest *)xpr_serio);
  950.  
  951.   qtimer(Timeout);
  952.  
  953.   WaitSigs=(1L<<tport->mp_SigBit) || (1L<<NewPort->mp_SigBit);
  954.   if (TWindowOpen) WaitSigs|=(1L << XPRWin->UserPort->mp_SigBit);
  955.  
  956.   ReturnedSigs=Wait(WaitSigs);
  957.  
  958.   if (ReturnedSigs & (1L << XPRWin->UserPort->mp_SigBit))
  959.   {
  960. #ifdef debugmode
  961.     puts("window flag");
  962. #endif
  963.     if (xpr_chk4abort()==-1)
  964.     {
  965.       // abort everything, tidy up and return -1
  966.  
  967.       if (!CheckIO((struct IORequest *)xpr_serio))
  968.       {
  969.         AbortIO((struct IORequest *)xpr_serio);
  970.       }
  971.       WaitIO((struct IORequest *)xpr_serio);
  972.  
  973.       AbortIO((struct IORequest *)treq);
  974.       WaitIO((struct IORequest *)treq);
  975.  
  976.       // cancel the transfer!
  977.       xpr_swrite(ZModemCancel,20);
  978.  
  979.       #ifdef debugmode
  980.       puts("xpr_sread, returning -1, aborted!");
  981.       #endif
  982.       return((LONG)-1);
  983.     }
  984.     // if we get here then it was not a cancel message that we received from
  985.     // the window, so we can sit in the main loop abit more and wait for
  986.     // another signal..
  987.   }
  988.  
  989.   if (ReturnedSigs&(1L<<NewPort->mp_SigBit))
  990.   {
  991.     #ifdef debugmode
  992.     puts("Serial Flag");
  993.     #endif
  994.     if (!CheckIO((struct IORequest *)xpr_serio))
  995.     {
  996.       AbortIO((struct IORequest *)xpr_serio);
  997.     }
  998.     WaitIO((struct IORequest *)xpr_serio);
  999.  
  1000.     // and cleanup the timer and serial requests
  1001.     AbortIO((struct IORequest *)treq);
  1002.     WaitIO((struct IORequest *)treq);
  1003.  
  1004.     // and just in case any bytes were read by the serial port, return the amount
  1005.     // would be 0 if a timeout occured and no data was read
  1006.  
  1007.     #ifdef debugmode
  1008.     printf("xpr_sread, returning %ld\n",xpr_serio->IOSer.io_Actual);
  1009.     #endif
  1010.     return((LONG)xpr_serio->IOSer.io_Actual);
  1011.   }
  1012.  
  1013.   if (ReturnedSigs&(1L<<tport->mp_SigBit))
  1014.   {
  1015.     #ifdef debugmode
  1016.     puts("Timer Flag");
  1017.     #endif
  1018.     if (!CheckIO((struct IORequest *)xpr_serio))
  1019.     {
  1020.       AbortIO((struct IORequest *)xpr_serio);
  1021.     }
  1022.     WaitIO((struct IORequest *)xpr_serio);
  1023.  
  1024.     AbortIO((struct IORequest *)treq);
  1025.     WaitIO((struct IORequest *)treq);
  1026.  
  1027.     #ifdef debugmode
  1028.     printf("xpr_sread, returning %ld\n",xpr_serio->IOSer.io_Actual);
  1029.     #endif
  1030.     return((LONG)xpr_serio->IOSer.io_Actual);
  1031.   }
  1032.  
  1033.   // Should Never Get Here, if it does a false signal arrived!
  1034.   DOOR_SysopText("XPR Error - SR1\r\n");
  1035.   return(0);
  1036. }
  1037.  
  1038. LONG __saveds __asm xpr_sflush(void)
  1039. {
  1040. #ifdef debugmode
  1041.   printf("xpr_sflush\n");
  1042. #endif
  1043.  
  1044.   xpr_serio->IOSer.io_Command=CMD_FLUSH;
  1045.   DoIO((struct IORequest *)xpr_serio);
  1046.   return((LONG)xpr_serio->IOSer.io_Error);
  1047. }
  1048.  
  1049. #define ST_PARTYON  (1 << 0)
  1050. #define ST_PARTYODD (1 << 1)
  1051. #define ST_7WIRE  (1 << 2)
  1052. #define ST_QBREAK (1 << 3)
  1053. #define ST_RADBOOGIE  (1 << 4)
  1054. #define ST_SHARED (1 << 5)
  1055. #define ST_EOFMODE  (1 << 6)
  1056. #define ST_XDISABLED  (1 << 7)
  1057. #define ST_PARTYMARKON  (1 << 8)
  1058. #define ST_PARTYMARK  (1 << 9)
  1059. #define ST_2BITS  (1 << 10)
  1060. #define ST_READ7  (1 << 11)
  1061. #define ST_WRITE7 (1 << 12)
  1062.  
  1063. LONG __saveds __asm xpr_setserial(register __d0 LONG Status)
  1064. {
  1065.   STATIC LONG XprBauds[12] =
  1066.   {
  1067.     110,
  1068.     300,
  1069.     1200,
  1070.     2400,
  1071.     4800,
  1072.     9600,
  1073.     19200,
  1074.     31250,
  1075.     38400,
  1076.     57600,
  1077.     76800,
  1078.     115200
  1079.   };
  1080.  
  1081.   LONG Return,i;
  1082.  
  1083. #ifdef debugmode
  1084.   printf("xpr_setserial, status = %ld\n",Status);
  1085. #endif
  1086.  
  1087.   xpr_serio -> IOSer . io_Command = SDCMD_QUERY;
  1088.   DoIO((struct IORequest *)xpr_serio);
  1089.  
  1090.   Return = xpr_serio -> io_SerFlags & 0xFF;
  1091.  
  1092.   if(xpr_serio -> io_ExtFlags & SEXTF_MSPON)
  1093.     Return |= ST_PARTYMARKON;
  1094.  
  1095.   if(xpr_serio -> io_ExtFlags & SEXTF_MARK)
  1096.     Return |= ST_PARTYMARK;
  1097.  
  1098.   if(xpr_serio -> io_StopBits == 2)
  1099.     Return |= ST_2BITS;
  1100.  
  1101.   if(xpr_serio -> io_ReadLen == 7)
  1102.     Return |= ST_READ7;
  1103.  
  1104.   if(xpr_serio -> io_WriteLen == 7)
  1105.     Return |= ST_WRITE7;
  1106.  
  1107.   for(i = 0 ; i < 12 ; i++)
  1108.   {
  1109.     if(xpr_serio -> io_Baud == XprBauds[i])
  1110.     {
  1111.       Return |= (i << 16);   // uses 16MSB's of the LONGWORD for the speed ?
  1112.  
  1113.       break;
  1114.     }
  1115.   }
  1116.  
  1117.   if(Status != -1)
  1118.   {
  1119.     xpr_serio -> IOSer . io_Command = SDCMD_SETPARAMS;
  1120.  
  1121.     xpr_serio -> io_SerFlags    = Status & 0xFF;
  1122.     xpr_serio -> io_ExtFlags    = 0;
  1123.  
  1124.     if(Status & ST_PARTYMARKON)
  1125.       xpr_serio -> io_ExtFlags |= SEXTF_MSPON;
  1126.  
  1127.     if(Status & ST_PARTYMARK)
  1128.       xpr_serio -> io_ExtFlags |= SEXTF_MARK;
  1129.  
  1130.     if(Status & ST_2BITS)
  1131.       xpr_serio -> io_StopBits = 2;
  1132.     else
  1133.       xpr_serio -> io_StopBits = 1;
  1134.  
  1135.     if(Status & ST_READ7)
  1136.       xpr_serio -> io_ReadLen = 7;
  1137.     else
  1138.       xpr_serio -> io_ReadLen = 8;
  1139.  
  1140.     if(Status & ST_WRITE7)
  1141.       xpr_serio -> io_WriteLen = 7;
  1142.     else
  1143.       xpr_serio -> io_WriteLen = 8;
  1144.  
  1145.     DoIO((struct IORequest *)xpr_serio);
  1146.  
  1147.   }
  1148.  
  1149.   return(Return);
  1150.  
  1151. }
  1152. /* EOT [end of theft] */
  1153.  
  1154. void OpenTransferWindow( void )
  1155. {
  1156.   struct Screen *Scr=NULL;
  1157.  
  1158.   if (!TWindowOpen)
  1159.   {
  1160.     if (HBBSFont=OpenDiskFont( &HBBS8066 ) )
  1161.     {
  1162.       if (N_ND->ConOK && N_ND->NodeSettings.UseOwnScreen)
  1163.       {
  1164.         sprintf(outstr,"NodeWatch_%d",N_ND->NodeNum);
  1165.         Scr = LockPubScreen(outstr);
  1166.       }
  1167.       if (!Scr)
  1168.       {
  1169.         Scr = LockPubScreen( "CtrlScrn" );
  1170.       }
  1171.       if (Scr)
  1172.       {
  1173.         if (OpenWindowXPRWin(Scr)==0)
  1174.         {
  1175.           // Opened OK
  1176.           TWindowOpen=TRUE;
  1177.         }
  1178.         UnlockPubScreen( NULL, Scr);
  1179.       }
  1180.     }
  1181.   }
  1182. }
  1183.  
  1184. void CloseTransferWindow( void )
  1185. {
  1186.   if (HBBSFont) CloseFont(HBBSFont);
  1187.   if (TWindowOpen)
  1188.   {
  1189.     CloseWindowXPRWin();
  1190.     TWindowOpen=FALSE;
  1191.   }
  1192. }
  1193.  
  1194. void KeepFlushing( void )
  1195. {
  1196.   BOOL Done=FALSE;
  1197.  
  1198.   do
  1199.   {
  1200.     switch(DOOR_GetLine(GL_IMMEDIATE,'\0',1,2,NULL))
  1201.     {
  1202.       case IN_LOSSCARRIER:
  1203.       case IN_TIMEOUT:
  1204.         Done=TRUE;
  1205.         break;
  1206.     }
  1207.   } while (!Done);
  1208. }
  1209.  
  1210. void Xfer( void )
  1211. {
  1212.   if (XProtocolBase=OpenLibrary(xprlibname,0))
  1213.   {
  1214.     if (xio=(struct XPR_IO*)AllocVec(sizeof (struct XPR_IO),MEMF_CLEAR))
  1215.     {
  1216.       xio->xpr_fopen     = xpr_fopen;
  1217.       xio->xpr_fclose    = xpr_fclose;
  1218.       xio->xpr_fread     = xpr_fread;
  1219.       xio->xpr_fwrite    = xpr_fwrite;
  1220.  
  1221.       xio->xpr_swrite    = xpr_swrite;
  1222.       xio->xpr_sread     = xpr_sread;
  1223.       xio->xpr_sflush    = xpr_sflush;
  1224.       xio->xpr_setserial = xpr_setserial;
  1225.  
  1226.       xio->xpr_update    = xpr_displayupdate;
  1227.       xio->xpr_chkabort  = xpr_chk4abort;
  1228.       xio->xpr_ffirst    = xpr_ffirst;
  1229.       xio->xpr_fnext     = xpr_fnext;
  1230.       xio->xpr_finfo     = xpr_finfo;
  1231.       xio->xpr_fseek     = xpr_fseek;
  1232.       xio->xpr_gets      = xpr_gets;
  1233.       xio->xpr_unlink    = xpr_unlink;
  1234.  
  1235.       AbortSerRead();
  1236.  
  1237.       if (GrabSerial())
  1238.       {
  1239.         // from this point on DON'T USE DOOR_WriteText(), use DOOR_SysopText() instead!
  1240.         // or you will corrupt the transfer!
  1241.  
  1242.         if (opentimer()==0)
  1243.         {
  1244.  
  1245.           xio->xpr_filename=xprlibopts;
  1246.  
  1247.  
  1248. //          DOOR_SysopText("protocol options= \"");
  1249. //          if (xprlibopts) DOOR_SysopText(xprlibopts);
  1250. //          DOOR_SysopText("\"\r\n");
  1251.  
  1252.           OpenTransferWindow();
  1253.  
  1254.           if(XProtocolSetup(xio))
  1255.           {
  1256.  
  1257.             if (UL_Files) // Uploading ??
  1258.             {
  1259.               // init filename with finename of first the first..
  1260.  
  1261.               xio->xpr_filename=HBBS_ListName(UL_FileList,0);
  1262.               TransferType=T_SEND;
  1263.               XProtocolSend(xio);
  1264.             }
  1265.             else // nope, Downloading ?
  1266.             {
  1267.               if (DL_PathOK)
  1268.               {
  1269.                 // Yup...
  1270.  
  1271.                 // init filename with path to download files..
  1272.  
  1273.                 xio->xpr_filename=DL_Path;
  1274.  
  1275.                 TransferType=T_RECEIVE;
  1276.                 XProtocolReceive(xio);
  1277.               }
  1278.             }
  1279.             XProtocolCleanup(xio);
  1280.           }
  1281.  
  1282.           CloseTransferWindow();
  1283.  
  1284.           closetimer();
  1285.         }
  1286.         else
  1287.         {
  1288.           DOOR_SysopText("Failed To Open Timer!\r\n");
  1289.         }
  1290.         ReleaseSerial();
  1291.  
  1292.         KeepFlushing();
  1293.  
  1294.       }
  1295.       else
  1296.       {
  1297.         DOOR_WriteText("Failed To Open Serial!\r\n");
  1298.       }
  1299.       FreeVec(xio);
  1300.     }
  1301.     CloseLibrary(XProtocolBase);
  1302.   }
  1303.   else
  1304.   {
  1305.     DOOR_WriteText("Failed to open \"");
  1306.     DOOR_WriteText(xprlibname);
  1307.     DOOR_WriteText("\" Exiting!\r\n");
  1308.   }
  1309.  
  1310. }
  1311.  
  1312. void CheckULList(void)
  1313. {
  1314.   struct FileBuffer *node;
  1315.   struct TaggedFile *Tag;
  1316.  
  1317.   for (node = (struct FileBuffer *)UL_FileList->lh_Head ; node->node.ln_Succ ; node =(struct FileBuffer *)node->node.ln_Succ)
  1318.   {
  1319.     if (node->ActualSize==node->BytesTransferred)
  1320.     {
  1321.       N_ND->Actions[ACTN_DOWNLOAD]=ACTC_DOWNLOAD;
  1322.  
  1323.       // transferred the file ok, remove creds (if applicable)
  1324.       // and write to callers log and ul/dl log..
  1325.  
  1326.       sprintf(outstr,"DOWNLOADED File:\"%s\" Size:%ld",node->node.ln_Name,node->ActualSize);
  1327.       HBBS_AddToCallersLog(outstr);
  1328.  
  1329.       N_ND->User.CallData.ActualDownloadFiles++;
  1330.       N_ND->User.NormalData.ActualDownloadFiles++;
  1331.       N_ND->User.CallData.ActualDownloadBytes+=node->ActualSize;
  1332.       N_ND->User.NormalData.ActualDownloadBytes+=node->ActualSize;
  1333.  
  1334.       N_ND->User.FilesDownloaded++;
  1335.       N_ND->User.BytesDownloaded+=node->ActualSize;
  1336.  
  1337.       if (Tag=HBBS_FindTag(node->node.ln_Name,TRUE))
  1338.       {
  1339.         if (TakeCreds && Tag->WarezFile && node->BlocksTransferred && N_ND->User.Valid && node->ReadFile)
  1340.         {
  1341.           sprintf(outstr,ANSI_RESET ANSI_FG_CYAN "Removing "ANSI_FG_WHITE"%6ld"ANSI_FG_CYAN" credits for file: "ANSI_FG_WHITE"%s\r\n",node->ActualSize,FilePart(node->node.ln_Name));
  1342.           DOOR_WriteText(outstr);
  1343.  
  1344.           N_ND->User.CallData.DownloadFiles++;
  1345.           N_ND->User.NormalData.DownloadFiles++;
  1346.  
  1347.           N_ND->User.CallData.DownloadBytes+=Tag->FileSize;
  1348.           N_ND->User.NormalData.DownloadBytes+=Tag->FileSize;
  1349.         }
  1350.  
  1351.         // and remove the tagged file
  1352.  
  1353.         N_ND->TaggedFiles--; // first! :-)
  1354.         Remove((struct Node*)Tag);
  1355.  
  1356.         FreeStr(Tag->node.ln_Name);
  1357.         FreeVec(Tag);
  1358.       }
  1359.  
  1360.  
  1361.     }
  1362.     else
  1363.     {
  1364.       // *C* add U/D log too..
  1365.       // failed transferring that file, leave it tagged and write to the log..
  1366.       sprintf(outstr,"FAILED DOWNLOAD File:\"%s\" Size:%ld Transferred:%ld",node->node.ln_Name,node->ActualSize,node->BytesTransferred);
  1367.       HBBS_AddToCallersLog(outstr);
  1368.       N_ND->Actions[ACTN_FAILEDDOWNLOAD]=ACTC_FAILEDDOWNLOAD;
  1369.  
  1370.     }
  1371.   }
  1372. }
  1373.  
  1374. void CheckDLList(void)
  1375. {
  1376.   struct FileBuffer *node;
  1377.  
  1378.   for (node = (struct FileBuffer *)DL_FileList->lh_Head ; node->node.ln_Succ ; node =(struct FileBuffer *)node->node.ln_Succ)
  1379.   {
  1380.     if (node->ActualSize==node->BytesTransferred)
  1381.     {
  1382.       // transferred the file ok, add creds (if applicable)
  1383.       // and write to callers log and ul/dl log..
  1384.  
  1385.       N_ND->User.CallData.ActualUploadFiles++;
  1386.       N_ND->User.NormalData.ActualUploadFiles++;
  1387.       N_ND->User.CallData.ActualUploadBytes+=node->ActualSize;
  1388.       N_ND->User.NormalData.ActualUploadBytes+=node->ActualSize;
  1389.  
  1390.       N_ND->User.FilesUploaded++;
  1391.       N_ND->User.BytesUploaded+=node->ActualSize;
  1392.  
  1393.       sprintf(outstr,"UPLOADED File:\"%s\" Size:%ld",node->node.ln_Name,node->ActualSize);
  1394.       HBBS_AddToCallersLog(outstr);
  1395.       N_ND->Actions[ACTN_UPLOAD]=ACTC_UPLOAD;
  1396.  
  1397.  
  1398.     }
  1399.     else
  1400.     {
  1401.       // *C* add U/D log too..
  1402.       // failed transferring that file, leave it tagged and write to the log..
  1403.  
  1404.       N_ND->Actions[ACTN_FAILEDUPLOAD]=ACTC_FAILEDUPLOAD;
  1405.  
  1406.       sprintf(outstr,"FAILED UPLOAD File:\"%s\" Size:%ld Transferred:%ld",node->node.ln_Name,node->ActualSize,node->BytesTransferred);
  1407.       HBBS_AddToCallersLog(outstr);
  1408.  
  1409.  
  1410.       sprintf(outstr,ANSI_RESET ANSI_FG_CYAN "Moving failed file"ANSI_FG_BLUE": "ANSI_FG_WHITE"%s"ANSI_FG_CYAN" Size"ANSI_FG_BLUE": "ANSI_FG_WHITE"%ld\r\n",node->node.ln_Name,node->BytesTransferred);
  1411.       DOOR_WriteText(outstr);
  1412.  
  1413.       sprintf(outstr,"%s@%ld",node->node.ln_Name,N_ND->User.CallData.UserID);
  1414.  
  1415.       if (Rename(node->node.ln_Name,outstr))
  1416.       {
  1417.         sprintf(outstr,"%sPARTUPLOAD %s@%ld",N_ND->OnlineStatus==OS_ONLINE ? "" : "NOUSER ",FilePart(node->node.ln_Name),N_ND->User.CallData.UserID); // move NOUSER to the door's system options!!!
  1418.         DOOR_SystemDoor("MoveFile",outstr);
  1419.       }
  1420.       else
  1421.       {
  1422.         DeleteFile(node->node.ln_Name);
  1423.       }
  1424.  
  1425.     }
  1426.   }
  1427. }
  1428.  
  1429. void DoorMain(int argc,char *argv[])
  1430. {
  1431.   long loop;
  1432.  
  1433.   BOOL AddTags=0;
  1434.   BOOL SystemFiles=TRUE;
  1435.   BOOL WarezFiles=TRUE;
  1436.  
  1437.   struct TaggedFile *Tag;
  1438.   struct FileBuffer *NewFileNode;
  1439.   char tmpname[1024];
  1440.  
  1441.   BPTR FL;
  1442.   struct FileInfoBlock FB;
  1443.  
  1444.  
  1445.   if (UL_FileList=HBBS_CreateList())
  1446.   {
  1447.     if (DL_FileList=HBBS_CreateList())
  1448.     {
  1449.       xprlibname=argv[2];
  1450.  
  1451.       // add list of tagged files to our list of files to transfer..
  1452.  
  1453.  
  1454.       // then check the parameters to see if we have any other options..
  1455.       // remembering to miss out the arguments that we've already checked
  1456.       // (hence starting the loop from startparam)
  1457.  
  1458.       for(loop=3;loop<argc;loop++) // if there are any parameters then display them
  1459.       {
  1460.         switch(toupper(argv[loop][0]))
  1461.         {
  1462.           case 'S' :
  1463.             CheckConfPaths=TRUE;
  1464.             break;
  1465.  
  1466.           case 'C' :
  1467.             TakeCreds=TRUE;
  1468.             break;
  1469.  
  1470.           case 'U' :
  1471.             strcpy(tmpname,&argv[loop][2]);
  1472.             if (!(FL=Lock(tmpname,SHARED_LOCK))) // does the file exist ?
  1473.             {
  1474.               if (UL_PathOK)
  1475.               {
  1476.                 strcpy(tmpname,UL_Path);
  1477.                 strcat(tmpname,&argv[loop][2]); // same as argv[loop]+2, start at 3rd char..
  1478.                 FL=Lock(tmpname,SHARED_LOCK);
  1479.               }
  1480.             }
  1481.             if (FL)
  1482.             {
  1483.               if (Examine(FL,&FB))
  1484.               {
  1485.                 if (NewFileNode=(struct FileBuffer*)HBBS_CreateNode(tmpname,sizeof(struct FileBuffer)))
  1486.                 {
  1487.                    // all othe rparams are set to null by HBBS_CreateNode()
  1488.                   NewFileNode->ActualSize=FB.fib_Size;
  1489.                   AddTail(UL_FileList,(struct Node *)NewFileNode);
  1490.                   UL_Files++;
  1491.                 }
  1492.  
  1493.               }
  1494.               UnLock(FL);
  1495.             }
  1496.  
  1497.             break;
  1498.  
  1499.           case 'O' :
  1500.             xprlibopts=&argv[loop][2];
  1501.             break;
  1502.  
  1503.           case 'D' :
  1504.             if (!DL_PathOK) // only allowed ONE download path!
  1505.             {
  1506.               DL_Path=&argv[loop][2];
  1507.               if (PathOK(DL_Path)) DL_PathOK=TRUE;
  1508.             }
  1509.             break;
  1510.  
  1511.           case 'W' :
  1512.             if (!UL_PathOK) // only allowed ONE download path!
  1513.             {
  1514.               UL_Path=&argv[loop][2];
  1515.               if (PathOK(UL_Path)) UL_PathOK=TRUE;
  1516.             }
  1517.             break;
  1518.  
  1519.           default:
  1520.             if (stricmp(argv[loop],"TAGS")==0)
  1521.             {
  1522.               AddTags=TRUE;
  1523.             }
  1524.  
  1525.             if (stricmp(argv[loop],"NOSYSTEM")==0)
  1526.             {
  1527.               SystemFiles=FALSE;
  1528.             }
  1529.  
  1530.             if (stricmp(argv[loop],"NOWAREZ")==0)
  1531.             {
  1532.               WarezFiles=FALSE;
  1533.             }
  1534.  
  1535.             break;
  1536.  
  1537.         }
  1538.       }
  1539.  
  1540.       if (AddTags)
  1541.       {
  1542.         if (N_ND->TaggedFiles)
  1543.         {
  1544.           for (Tag=(struct TaggedFile *)N_ND->TaggedFileList->lh_Head;Tag->node.ln_Succ;Tag=(struct TaggedFile *)Tag->node.ln_Succ)
  1545.           {
  1546.             if (((Tag->WarezFile==TRUE) && (WarezFiles)) || ((Tag->WarezFile==FALSE) && (SystemFiles)))
  1547.             {
  1548.               if (NewFileNode=(struct FileBuffer*)HBBS_CreateNode(Tag->node.ln_Name,sizeof(struct FileBuffer)))
  1549.               {
  1550.                 NewFileNode->ActualSize=Tag->FileSize;
  1551.                 AddTail(UL_FileList,(struct Node*)NewFileNode);
  1552.                 UL_Files++;
  1553.               }
  1554.             }
  1555.           }
  1556.         }
  1557.       }
  1558.  
  1559.       if ((xprlibname) && ((UL_Files || DL_PathOK)) )
  1560.       {
  1561.         Xfer();
  1562.       }
  1563.       DOOR_WriteText("\r\n");
  1564.  
  1565.       CheckDLList();
  1566.       FreeStrList(DL_FileList); // then free it!
  1567.     }
  1568.     CheckULList();
  1569.     FreeStrList(UL_FileList);
  1570.  
  1571.  
  1572.     HBBS_SaveUserData(&N_ND->User.NormalData);
  1573.     // just in case the user decided to loose carrier! :-)
  1574.     // or if the bbs crashed (heaven forbid..) before the data was saved normally.
  1575.   }
  1576. }
  1577.  
  1578. int main(int argc,char *argv[])
  1579. {
  1580.   if (sscanf(argv[1],"%d",&N_NodeNum)==0)
  1581.   {
  1582.     printf("Invalid/No Paramaters for door!\n");
  1583.     exit (20);
  1584.   }
  1585.   init("XPR");
  1586.  
  1587.   SetTaskPri(FindTask(0),2); // *C* make configurable!!!
  1588.  
  1589.   if (BBSGlobal=HBBS_GimmeBBS())
  1590.   {
  1591.     if (N_ND=HBBS_NodeDataPtr(N_NodeNum)) // this should not fail in normal circumstances..
  1592.     {
  1593.       DoorMain(argc,argv);
  1594.     }
  1595.   }
  1596.   cleanup(0);
  1597. }
  1598.